import tushare as ts

import pandas as pd

pd.set_option('display.max_columns',1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth',1000)

windowSize = 10

code = '000001'

stockList = ts.get_k_data(code=code, start='2019-01-01', ktype='D', autype='qfq')
stockList.index = stockList.pop('date')

stockList['mean10'] = stockList['close'].rolling(10).mean()
stockList['pre_mean10'] = stockList['mean10'].shift(1)
stockList['mean5'] = stockList['close'].rolling(5).mean()
stockList['pre_mean5'] = stockList['mean5'].shift(1)
# print(stockList)

stockList['signalsUp'] = (stockList['mean5'].shift(1) < stockList['mean10'].shift(1)) & (stockList['mean5'] >= stockList['mean10'])
stockList['signalsDown'] = (stockList['mean5'].shift(1) > stockList['mean10'].shift(1)) & (stockList['mean5'] <= stockList['mean10'])

resutlUp = stockList[stockList['signalsUp']]
print(resutlUp)
resultDown = stockList[stockList['signalsDown']]
print(resultDown)